<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class CommonController extends Controller
{
    // 顶部栏目导航
    public function getNavi()
    {
        // 导航栏
        $navi = new \App\Models\Type;
        $naviData = $navi->getNavi();
        return $naviData;
    }

    /**
     * 本栏目文章点击排行
     * @param int $type_id
     * @return mixed
     */
    public function articleClick($type_id = 0)
    {
        $data = DB::table('articles')->where(function($query) use ($type_id){
            if($type_id){
                $query->where('type_id', $type_id);
            }
        })->orderBy('click', 'desc')->orderBy('id', 'desc')->offset(0)->limit(8)->get();
        return $data;
    }

    /**
     * 本栏目文章点赞排行
     * @param int $type_id
     * @return mixed
     */
    public function articlePraise($type_id = 0)
    {
        $data = DB::table('articles')->where(function($query) use ($type_id){
            if($type_id){
                $query->where('type_id', $type_id);
            }
        })->orderBy('praise', 'desc')->orderBy('id', 'desc')->offset(0)->limit(8)->get();
        return $data;
    }

    // 获取tags列表
    public function getTags()
    {
        return DB::table('tags')->orderBy('weight', 'desc')->limit(20)->get();
    }
}
